import sys
sys.path.append("..")
import json
from flask import request
from create_id import get_id
from db_client import *


def get_demand():
    demand_id = request.args.get('search')
    demand_list = []
    states = {
        '未采购': 0,
        '已规划': 1,
        '已过审': 2,
        '采购中': 3,
        '已完成': 4
    }
    results = mysql_client.get_demand(demand_id)
    for result in results:
        data = {
            'id': result[0],
            'department': result[1],
            'item_id': result[2],
            'item_name': result[3],
            'count': result[4],
            'date': result[5],
            'demand_input_person': result[6],
            'state': result[7],
            'demand_file_id': result[8]
        }
        demand_list.append(data)
    return demand_list

